package top.wu2020.lazy.ws.chat.infrastructure.persistence;

import top.wu2020.lazy.ws.chat.infrastructure.entity.CommunityLikeRecordDO;
import top.wu2020.lazy.ws.chat.infrastructure.converter.CommunityLikeRecordConverter;
import top.wu2020.lazy.ws.chat.infrastructure.mapper.CommunityLikeRecordMapper;
import top.wu2020.lazy.ws.chat.domain.model.community.like.record.CommunityLikeRecordRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import top.wu2020.lazy.ws.chat.domain.model.community.like.record.CommunityLikeRecord;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe community_like_record 
 *
 * @author Jia wei Wu
 * @date 2024/05/24 08:52 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class CommunityLikeRecordRepositoryImpl  implements  CommunityLikeRecordRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增
     *
     * @param communityLikeRecord 新增     
     * @return {@link Result<CommunityLikeRecord>} 新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityLikeRecord> story(CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        lazyLambdaStream.upsert(communityLikeRecordDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增
     *
     * @param communityLikeRecordList 批量新增     
     * @return {@link Result<List<CommunityLikeRecord>>} 新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityLikeRecord>> batchStory(List<CommunityLikeRecord> communityLikeRecordList) {
        List<CommunityLikeRecordDO> communityLikeRecordDOList = communityLikeRecordList.stream().map(CommunityLikeRecordConverter.INSTANCE::fromCommunityLikeRecord).collect(Collectors.toList());
        lazyLambdaStream.upsert(communityLikeRecordDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个
     *
     * @param communityLikeRecord 查询单个     
     * @return {@link Result<CommunityLikeRecord>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityLikeRecord> findOne(CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        CommunityLikeRecord communityLikeRecordOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(communityLikeRecordDO), CommunityLikeRecord.class);
        return ResultFactory.successOf(communityLikeRecordOne);
    }

    /**
     * describe 查询多个
     *
     * @param communityLikeRecord 查询多个     
     * @return {@link Result<List<CommunityLikeRecord>>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityLikeRecord>> findList(CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        List<CommunityLikeRecord> communityLikeRecordList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(communityLikeRecordDO), CommunityLikeRecord.class);
        return ResultFactory.successOf(communityLikeRecordList);
    }

    /**
     * describe 分页查询多个
     *
     * @param size 当前页数
     * @param current 当前页
     * @param communityLikeRecord 分页查询多个     
     * @return {@link Result<LazyPage<CommunityLikeRecord>>} 分页领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<LazyPage<CommunityLikeRecord>> findPage(int size,int current,CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        LazyPage<CommunityLikeRecord> lazyPage = new LazyPage<>(current,size);
        LazyPage<CommunityLikeRecord> communityLikeRecordLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(communityLikeRecordDO),lazyPage, CommunityLikeRecord.class);
        return ResultFactory.successOf(communityLikeRecordLazyPage);
    }

    /**
     * describe 删除
     *
     * @param communityLikeRecord 删除     
     * @return {@link Result<CommunityLikeRecord>}      
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityLikeRecord> remove(CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(communityLikeRecordDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在
     *
     * @param communityLikeRecord 领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<Boolean> exists(CommunityLikeRecord communityLikeRecord) {
        CommunityLikeRecordDO communityLikeRecordDO = CommunityLikeRecordConverter.INSTANCE.fromCommunityLikeRecord(communityLikeRecord);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(communityLikeRecordDO));
        return ResultFactory.successOf(exists);
    }

}